﻿<%@ WebHandler Language="C#" Class="SysUser_GetByPage" %>

using System;
using System.Web;
using System.Text;
using Newtonsoft.Json;
public class SysUser_GetByPage : IHttpHandler , System.Web.SessionState.IReadOnlySessionState
{
    
    public void ProcessRequest (HttpContext context) 
    {
        OTS.Common.Page<OTS.Model.saleOrder> page = new OTS.Common.Page<OTS.Model.saleOrder>();
        if (!OTS.BaseLogin.validataModule(context, (int)OTS.enumSysRight.SalesOrderManager))
        {
            page.success = false;
            page.msg = "非法操作！";
        }
        else
        {
            string limit = context.Request["limit"];
            string start = context.Request["start"];
            int limitInt = 20;
            int startInt = 0;
            if (null != limit && OTS.Common.Help.IsNumber(limit)) limitInt = int.Parse(limit);
            if (null != start && OTS.Common.Help.IsNumber(start)) startInt = int.Parse(start);

            string orderNO = context.Request["orderNO"];
            string loginname = context.Request["loginname"];
            string status = context.Request["status"];
            if (null == orderNO) orderNO = "";
            if (null == loginname) loginname = "";
            if (null == status) { status = ""; } else if (status == "-1"){   status = "";}

            OTS.BLL.SaleOrderBLL bll = new OTS.BLL.SaleOrderBLL();


            if (orderNO == "" && loginname == "" && status=="")
            {
                 page = bll.GetListByPage(startInt, limitInt, "");
            }    
            
            else
            {
                string strWhere = " 1=1 ";
                if (orderNO != "")
                {
                    strWhere += " AND orderNO= '" + OTS.DAL.DBUtility.Database.GetSQLString(orderNO) + "'";
                }
                if (loginname != "")
                {
                    OTS.BLL.CustomBLL bllCus = new OTS.BLL.CustomBLL();

                    int cusID = bllCus.GetCusIdByLoginName(loginname);
                    if (cusID > 0)
                    {
                        strWhere += "  AND salesOrder.cusID=" + cusID.ToString();

                    }
                    else
                    {
                        strWhere += " AND 1=2 ";
                        //strWhere += " AND cusLoginName = '" + OTS.DAL.DBUtility.Database.GetSQLString(loginname) + "'";
                    }
                }
                if (status == "0" || status == "1" || status == "2" || status == "3")
                {
                    strWhere += " AND status =" + OTS.DAL.DBUtility.Database.GetSQLString(status);
                }
                page = bll.GetListByPage(startInt, limitInt,  strWhere);
            }



        } 
        context.Response.ContentType = "application/x-json";
        context.Response.Charset = "utf-8";
        context.Response.Write(JavaScriptConvert.SerializeObject(page));
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}